package com.shujia.jinjie;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class MySqlTool {


    public static Connection getConnection() {
        Connection conn = null;
        try {
            Properties properties = new Properties();
            properties.load(new BufferedReader(new FileReader("redis/src/main/resources/mysqlInfo.properties")));

            String url1 = properties.getProperty("url");
            String username1 = properties.getProperty("username");
            String password1 = properties.getProperty("password");


            //1、加载驱动类
            // mysql驱动包5.1.xx版本中驱动类的路径：com.mysql.jdbc.Driver
            // mysql驱动包8.0.xx版本中驱动类的路径：com.mysql.cj.jdbc.Driver
            Class.forName("com.mysql.jdbc.Driver");

            //2、创建数据库连接对象
            //public static Connection getConnection(String url,String user, String password)
            /*
                url: 指定要连接的mysql服务地址以及数据库名
                    jdbc:mysql://master:3306/bigdata33?useUnicode=true&characterEncoding=utf-8
             */
//            String url = "jdbc:mysql://master:3306/bigdata33?useUnicode=true&characterEncoding=utf-8&useSSL=false";
//            String username = "root";
//            String password = "123456";
            conn = DriverManager.getConnection(url1, username1, password1);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return conn;
    }
}
